package leetcode20210927;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LUYAO
 * Date: 2021-09-27
 * Time: 16:25
 */
public class MinStack01 {
    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(3);
        minStack.push(5);
        minStack.push(1);
        minStack.push(2);
        minStack.push(4);



    }
}

//自己写的什么垃圾玩意？？？看看别人的思路
class MinStack {
    private Stack<Integer> stack1;
    private Stack<Integer> stack2;

    /** initialize your data structure here. */
    public MinStack() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();

    }

    public void push(int x) {
        stack1.push(x);
    }

    public void pop() {
        stack1.pop();
    }

    public int top() {
        int y = stack1.pop();
        stack1.push(y);
        return y;
    }

    public int min() {
        int count = stack1.pop();
        stack2.push(count);
        while(!stack1.isEmpty()){
            int n = stack1.pop();
            stack2.push(n);
            if(n < count){
                count = n;
            }
        }
        while(!stack2.isEmpty()){
            stack1.push(stack2.pop());
        }

        return count;

    }
}
